
import { ref } from 'vue'
export function debounce(func, wait) {
    let timeout;
    return function (...args) {
        clearTimeout(timeout);
        timeout = setTimeout(() => func.apply(this, args), wait);
    };
}

export function useFormattedNumber() {
    const formatNumber = (value) => {
        if (typeof value !== 'string' && typeof value !== 'number') {
            return { integer: value, decimal: '' }
        }

        const stringValue = String(value)
        const parts = stringValue.split('.')

        return {
            integer: parts[0],
            decimal: parts.length > 1 ? `.${parts[1]}` : ''
        }
    }

    return {
        formatNumber
    }
}

export function formatTimestamp(timestamp) {
    // 将时间戳转换为毫秒
    const date = new Date(timestamp * 1000);

    // 获取年月日时分秒
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1)
    const day = String(date.getDate()).padStart(2, '0');
    const hours = String(date.getHours()).padStart(2, '0');
    const minutes = String(date.getMinutes()).padStart(2, '0');
    const seconds = String(date.getSeconds()).padStart(2, '0');

    // 返回格式化的日期时间字符串
    return `${year}-${month}-${day} ${hours}:${minutes}`;
}